<!DOCTYPE html>
<html>
<head>
    <title>权限菜单节点</title>
    {include file="common/inc_meta" /}
</head>
<body>
 <div id="wrapper">
    {include file="common/inc_menu" /}
       <div id="page-wrapper" class="gray-bg">
          {include file="common/inc_top" /}
            <div class="row wrapper border-bottom white-bg page-heading" style="padding-top:20px;font-weight: normal;">
                <div class="col-sm-4">
                    <h2 style="margin-bottom:10px;">权限菜单节点</h2>
                    <ol class="breadcrumb">
                        <li><a href="{$admin.index_page}">主页</a></li>
                        <li><a>权限</a></li>
                        <li class="active"><strong>菜单节点</strong></li>
                    </ol>
                </div>
                <div class="col-lg-2"></div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">
                
               <div class="row">
                  <div class="col-lg-12">
                     <div class="ibox float-e-margins">
                        <div class="ibox-content" style="padding: 10px 10px 7px 10px; position: relative;">
                                <form role="form" class="form-inline resettokendiv" onsubmit="return false;">
                                    <div class="form-group">
                                          模块&nbsp;
                                          <select class="form-control" id="vModuleType">
                                            <option value="ALL">所有</option>
											{volist name="module_type_list" id="vo"}
                                            <option value="{$vo.id}">{$vo.name}</option>
											{/volist}
                                          </select>
                                    </div>
									<div class="form-group" style="margin-left:20px;">
                                          类型&nbsp;
                                          <select class="form-control" id="vType">
                                            <option value="ALL">所有</option>
                                            <option value="menu">菜单</option>
                                            <option value="file">节点</option>
                                          </select>
                                    </div>
                                    <div class="form-group" style="margin-left:20px;">
                                        关键词&nbsp;
                                        <input type="text" placeholder="菜单节点标题或URL路由" id="inputKeyWord" class="form-control">
                                    </div>
                                    &nbsp;&nbsp;
                                    <button data-toggle="button" class="btn btn-primary btn-outline" type="button" id="queryBtn">重新查询</button>
                                </form>
                                <div style="position: absolute; right:15px;top:13px;">
                                    <button data-toggle="button" class="btn btn-primary btn-sm" type="button" id="addBtn">新增</button>
                                </div>
                        </div>
                        <table class="table table-striped table-bordered table-hover white-bg">
                        <thead>
                            <tr>
                                  <th style="width:5%;text-align:center;">序号</th>
								  <th>所属模块</th>
                                  <th>标题</th>
                                  <th>URL路由</th>
                                  <th>图标</th>
                                  <th>排序</th>
                                  <th>状态</th>
                                  <th>创建时间</th>
                                  <th style="width:10%;text-align:center;">操作</th>
                            </tr>
                        </thead>
                        <tbody id="ListTable"></tbody>
                        <tfoot>
                            <tr>
                                  <th style="width:5%;text-align:center;">序号</th>
								  <th>所属模块</th>
                                  <th>标题</th>
                                  <th>URL路由</th>
                                  <th>图标</th>
                                  <th>排序</th>
                                  <th>状态</th>
                                  <th>创建时间</th>
                                  <th style="width:10%;text-align:center;">操作</th>
                            </tr>
                        </tfoot>
                        </table>
                        <div id="pagebox" style="padding:0px 10px 30px 0px;background: #ffffff;height:50px;text-align:right;"></div>
                      </div>
                   </div>
                 </div>


            </div>
     {include file="common/inc_footer" /}
     </div>
 </div>
<!-- Mainly scripts -->
{include file="common/inc_jsfile" /}
 {include file="common/back_top" /}
<script>
var _p = {$page}, _vmoduletype = 'ALL', _vtype = 'ALL', _keyword = '';
$(function(){
  //类型绑定
  $("#vModuleType").change(function(){
      _vmoduletype = $(this).val();
      _p = 1;
      getPageData();
  });
  //类型绑定
  $("#vType").change(function(){
      _vtype = $(this).val();
      _p = 1;
      getPageData();
  });
  //查询
  $("#queryBtn").click(function(){
     _keyword = $.trim($("#inputKeyWord").val());
     _p = 1;
     getPageData();
  });
  //新增
  $("#addBtn").click(function(){
     window.location.href = "{:url('admin/authrule/add')}";
  });
  getPageData();
});
//加载数据
function getPageData(){
 _Admin.ajax("{:url('admin/authrule/index')}",{page:_p,vmodtype:_vmoduletype,vtype:_vtype,word:_keyword},function(d){
   if(d.err == '0')
   {
      $('#ListTable').empty();
       $.each(d.list, function(i,v){  
         var _class = (i%2 ==0) ? "gradeB" : "gradeA";
         var _editLink = "{:url('admin/authrule/edit')}?id=" + v.id;
         var _editHtml = "<a href=\"" + _editLink + "\" class=\"btn btn-outline btn-primary btn-sm\">修改</a>";
         _editHtml += "&nbsp;&nbsp;&nbsp;<a onClick=\"delAction('" + v.id + "');\" class=\"btn btn-outline btn-warning btn-sm\">删除</a>";
         var mkTxt = '未知';
		 if(v.module_type == 'admin') mkTxt = '后台';
		 if(v.module_type == 'index_menu') mkTxt = '前台';
		 var html = '<tr class="' + _class + '" data-id="' + v.id + '" data-oldsort="' + v.sort + '">\
                <td style="width:5%;text-align:center;">' + parseInt(i+1) + '</td>\
				<td>' + mkTxt + '</td>\
                <td>' + v.title + '</td>\
                <td>' + v.url + '</td>\
                <td>' + v.icon + '</td>\
                <td style="width:5%;"><input type="text" class="form-control" name="MSortVal" value="' + v.sort + '"></td>\
                <td>' + v.status + '</td>\
                <td>' + v.create_time + '</td>\
                <td style="width:10%;text-align:center;">' + _editHtml + '</td>\
            </tr>';
         $('#ListTable').append(html);  
      });
      BindInputEdit();
      LoadPageBody(d.page, d.limit, d.total);  
   }else{
     _Admin.emptyTabel(d.msg,8,'#ListTable','#pagebox');  
   }
 });  
}
//参数 当前页 / 每页显示数量 / 总记录数
function LoadPageBody(_page = 0, _limit = 0, _count = 0)
{
 Laypage.render({
    elem: 'pagebox'
    ,curr: _page
    ,limit:_limit
    ,count: _count
    ,layout: ['count', 'prev', 'page', 'next', 'skip']
    ,jump: function(obj, first){
      _p = obj.curr;
      if(!first) getPageData();
    }
 });  
}
//删除
function delAction(_id)
{
    layer.confirm('您确定要删除当前的记录？', {
      btn: ['删除','取消']
    }, function(){
        _Admin.ajax("{:url('admin/authrule/del')}",{id:_id},function(d){
           layer.closeAll();
           if(d.err == '0')
           {
             layer.msg(d.msg, {time: 2000,anim: 4},function(){window.location.reload();});
           }else{
             layer.msg(d.msg, {time: 2000,anim: 4});
           }
         });
    }, function(){
      layer.closeAll();
    });
}
//input框内容修改排序值自动更新
function BindInputEdit()
{
  $(document).find('input[name="MSortVal"]').focus(function(){$(this).select();});
  $(document).find('input[name="MSortVal"]').on("keyup",function(){
     $(this).val($(this).val().replace(/[^\-?\d]/g,'0')); //$(this).parent().parent().data('id')
  });
  $(document).find('input[name="MSortVal"]').on("blur",function(){
     $(this).val($(this).val().replace(/[^\-?\d]/g,'0'));
     if($(this).parent().parent().data('oldsort') != $(this).val())
     {
       _Admin.ajax("{:url('admin/authrule/setsort')}",{id:$(this).parent().parent().data('id'),val:$.trim($(this).val())},function(d){
          if(d.err != '0')
          {
             layer.msg(d.msg, {time: 2000,anim: 6});
          }
       });
     }
  });
}
</script>
</body>
</html>
